#ifndef ODB_USER_HXX
#define ODB_USER_HXX

#include <boost/date_time/posix_time/posix_time.hpp>
#include <odb/core.hxx>
#include <odb/nullable.hxx>
#include <string>

namespace chat {
#pragma db object table("user")
class User {
   public:
    User() = default;

    /**
     * 手机号注册
     */
    User(const std::string& user_id, const std::string& phone)
        : user_id_(user_id), phone_(phone), nickname_("用户" + phone) {}

    /**
     * 用户名 密码 注册
     */
    User(const std::string& user_id, const std::string& nickname,
         const std::string password)
        : user_id_(user_id), nickname_(nickname), password_(password) {}

    void phone(const std::string& phone) { phone_ = phone; }
    const odb::nullable<std::string> phone() const { return phone_; }

    void user_id(const std::string& user_id) { user_id_ = user_id; }
    const std::string& user_id() const { return user_id_; }

    void nickname(const std::string& nickname) { nickname_ = nickname; }
    const std::string& nickname() const { return nickname_; }

    void description(const std::string& description) {
        description_ = description;
    }
    const odb::nullable<std::string> description() const {
        return description_;
    }

    void password(const std::string& password) { password_ = password; }
    const odb::nullable<std::string> password() const { return password_; }

    void avatar_id(const std::string& avatar_id) { avatar_id_ = avatar_id; }
    const odb::nullable<std::string> avatar_id() const { return avatar_id_; }

   private:
    friend class odb::access;
#pragma db id auto
    unsigned long id_;
#pragma db type("VARCHAR(64)") index unique
    odb::nullable<std::string> phone_;  // 手机号
#pragma db type("VARCHAR(64)") index unique
    std::string user_id_;  // 用户id
#pragma db type("VARCHAR(64)") index unique
    std::string nickname_;                    // 昵称
    odb::nullable<std::string> description_;  // 签名
#pragma db type("VARCHAR(64)")
    odb::nullable<std::string> password_;  // 密码
#pragma db type("VARCHAR(64)")
    odb::nullable<std::string> avatar_id_;  // 头像文件id
};

using UserPtr = std::shared_ptr<User>;
}  // namespace chat

#endif  // ODB_USER_HXX